<?php
namespace addons\jieziad\controller;

/**
 * @ApiSector (广告管理)
 * @package addons\jieziad\controller
 */
class Api extends \app\common\controller\Api
{
    protected $noNeedLogin = ['*'];

    /**
     * @ApiTitle (广告详细)
     * @ApiMethod (POST)
     * @ApiParams (name="id", type="integer", require=true, sample="0", description="广告位id")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
    "code": 1,
    "msg": "ok",
    "time": "1632991219",
    "data": [
    {
    "cont": "飞洒地方啊发生的法撒旦法撒旦发大水",
    "phone": "15011111222",
    "name": "bbb3333332",
    "id": 55,
    "is_default": 0
    }
    ]
    })
     */
    public function pos_info()
    {
        $pos_id = input('id', 0, 'intval');
        $result = [];
        if ($pos_id > 0) {
            $ad_service = new \addons\jieziad\service\Ad();
            $result = $ad_service->pos_info($pos_id);
        }
        
        // imgList: {title: "最多可添加10张图片，建议宽度750px", max: 10, list: [
        //  img: "https://data.wuht.net/uploads/attach/2021/08/20210823/7175ab97e5c96c475e6551cf23de2e5a.png",
        //  info: [
        //      {title: "标题", value: "", maxlength: 10, tips: "选填，不超过十个字"},
        //      {title: "链接", value: "", maxlength: 999, tips: "请填写链接"}
        //  ]
        // ]}
        // isShow: {val: true}
        
        
        $imgList['title']="最多可添加10张图片，建议宽度750px";
        $imgList['max']=10;
        foreach ($result as $k => $v) {
            $imgList['list'][$k]['img']=$v['ad_image'];
            $info[0]['title']="标题";
            $info[0]['value']=$v['ad_name'];
            $info[1]['title']="链接";
            $info[1]['value']=$v['ad_val'];
            
            $imgList['list'][$k]['info']=$info;
        }
        
        $result2['isShow']['val']='true';
        $result2['imgList']=$imgList;
        $this->success('ok', $result2);
    }

    /**
     * @ApiTitle (广告详细2)
     * @ApiMethod (POST)
     * @ApiParams (name="id", type="integer", require=true, sample="0", description="广告位id")
     */
    public function pos_info2()
    {
        $pos_id = input('id', 0, 'intval');
        $result = [];
        if ($pos_id > 0) {
            $ad_service = new \addons\jieziad\service\Ad();
            $result = $ad_service->pos_info($pos_id);
        }
        
        
        $this->success('ok', $result);
    }

    /**
     * @ApiTitle (广告详细(多个))
     * @ApiMethod (POST)
     * @ApiParams (name="ids", type="integer", require=true, sample="1,2,3", description="广告位ids,多个使用逗号拼接")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
    "code": 1,
    "msg": "ok",
    "time": "1632991219",
    "data": [
    {
    "cont": "飞洒地方啊发生的法撒旦法撒旦发大水",
    "phone": "15011111222",
    "name": "bbb3333332",
    "id": 55,
    "is_default": 0
    }
    ]
    })
     */
    public function pos_infos()
    {
        $pos_ids = input('ids');
        if ($pos_ids) {
            $tmp_ids = explode(',', $pos_ids);
            $pos_ids = [];
            foreach ($tmp_ids as $tmp_id) {
                $tmp_id = intval($tmp_id);
                if ($tmp_id > 0) {
                    $pos_ids[$tmp_id] = $tmp_id;
                }
            }
        }
        $result = [];
        if ($pos_ids) {
            $ad_service = new \addons\jieziad\service\Ad();
            $result = $ad_service->pos_infos($pos_ids);
        }
        $this->success('ok', $result);
    }
}
